package com.bluebench.bigul.service;

import java.util.HashMap;
import java.util.Map;

import com.bluebench.bigul.domain.ConstructorInvocation;
import com.bluebench.bigul.domain.EnumInvocation;
import com.bluebench.bigul.domain.FieldInvocation;
import com.bluebench.bigul.domain.GraphicInvocation;
import com.bluebench.bigul.domain.Invocation;
import com.bluebench.bigul.domain.Invoker;
import com.bluebench.bigul.domain.StaticInvocation;
import com.bluebench.bigul.domain.Types;

public class TypeFactory {
	
	static Map<String,Class<?>> primitiveMap = new HashMap<String,Class<?>>();
	
	static{
		
		primitiveMap.put("int", Integer.TYPE );
		primitiveMap.put("long", Long.TYPE );
		primitiveMap.put("double", Double.TYPE );
		primitiveMap.put("float", Float.TYPE );
		primitiveMap.put("boolean", Boolean.TYPE );
		primitiveMap.put("char", Character.TYPE );
		primitiveMap.put("byte", Byte.TYPE );
		primitiveMap.put("void", Void.TYPE );
		primitiveMap.put("short", Short.TYPE );
	}

	public static Invocation getInstance(String type){		
		Types t = Types.getType(type);
		Invocation invocation = null;
		
		switch(t.invocationType){
			case Invoker.CONSTRUCTOR:
				invocation = new ConstructorInvocation();
				invocation.setClassName(t.className);
				invocation.setType(t.type);
				break;
			case Invoker.STATIC:
				invocation = new StaticInvocation();
				((StaticInvocation)invocation).setMethodName(t.getStaticMethodName());
				invocation.setClassName(t.className);
				invocation.setType(t.type);
				break;
			case Invoker.ENUM:
				invocation = new EnumInvocation();
				invocation.setClassName(t.className);
				invocation.setType(t.type);
				break;
			case Invoker.FIELD:
				invocation = new FieldInvocation();
				invocation.setClassName(t.className);
				invocation.setField(t.type);
				break;
			case Invoker.GRAPHIC:
				invocation = new GraphicInvocation();
				invocation.setClassName(t.className);
				invocation.setType(t.type);
				break;
		}		
		
		return invocation;
	}
	
	public static Class<?> getPrimitiveType(String type){
		return primitiveMap.get(type);
	}
	
	
}
